/**
 * 文章的模式
 * 务必与数据库中的模式数据一致！
 */

const modes = [{
	"value": "01",
	"text": "古代文学体裁",
	"children": [{
		"value": "0101",
		"text": "诗歌",
		"children": [{
			"value": "010101",
			"text": "诗",
			"children": [{
				"value": "01010101",
				"text": "古风",
				"children": [{
					"value": "0101010103",
					"text": "三言"
				},{
					"value": "0101010104",
					"text": "四言"
				},{
					"value": "0101010105",
					"text": "五言"
				},{
					"value": "0101010107",
					"text": "七言"
				},{
					"value": "0101010198",
					"text": "其它"
				},{
					"value": "0101010199",
					"text": "混合"
				}]
			},{
				"value": "01010102",
				"text": "绝句",
				"children": [{
					"value": "0101010205",
					"text": "五言"
				},{
					"value": "0101010207",
					"text": "七言"
				}]
			},{
				"value": "01010103",
				"text": "律诗",
				"description": "如果是排律，则在后面补充钙排律的对数值。比如默认的五言律诗，应该是010101030504",
				"children": [{
					"value": "0101010305",
					"text": "五言"
				},{
					"value": "0101010307",
					"text": "七言"
				}]
			}]
		},{
			"value": "010102",
			"text": "词",
			"children": [{
				"value": "01010201",
				"text": "小令",
				"description": "58字以内"
			}, {
				"value": "01010202",
				"text": "中调",
				"description": "59~90字"
			}, {
				"value": "01010203",
				"text": "长调",
				"description": "91字以上"
			}]
		},{
			"value": "010103",
			"text": "曲"
		},{
			"value": "010109",
			"text": "歌",
			"description": "只有押韵，没有其它格律的古代歌曲。该类目一般不存在"
		}]
	},{
		"value": "0102",
		"text": "赋"
	},{
		"value": "0103",
		"text": "骈文"
	},{
		"value": "0104",
		"text": "原"
	},{
		"value": "0105",
		"text": "辩"
	},{
		"value": "0106",
		"text": "说"
	},{
		"value": "0107",
		"text": "论"
	},{
		"value": "0108",
		"text": "奏议"
	},{
		"value": "0109",
		"text": "序"
	},{
		"value": "0110",
		"text": "赠序"
	},{
		"value": "0111",
		"text": "铭"
	},{
		"value": "0112",
		"text": "祭文"
	},{
		"value": "0113",
		"text": "杂记"
	},{
		"value": "0114",
		"text": "游记"
	},{
		"value": "0115",
		"text": "童话"
	},{
		"value": "0116",
		"text": "民间故事"
	},{
		"value": "0117",
		"text": "寓言"
	},{
		"value": "0118",
		"text": "传说"
	},{
		"value": "0119",
		"text": "传奇"
	}]
},{
	"value": "02",
	"text": "现代文学体裁",
	"description": "小说与诗歌、散文、戏剧，并称“四大文学体裁”",
	"children": [{
		"value": "0201",
		"text": "诗歌",
		"children": [{
			"value": "020101",
			"text": "自由诗"
		},{
			"value": "020102",
			"text": "歌曲"
		}]
	},{
		"value": "0202",
		"text": "剧本"
	},{
		"value": "0203",
		"text": "小说",
		"children": [{
			"value": "020301",
			"text": "章回体"
		},{
			"value": "020302",
			"text": "日记体"
		},{
			"value": "020303",
			"text": "书信体"
		},{
			"value": "020304",
			"text": "自传体"
		}]
	},{
		"value": "0204",
		"text": "散文"
	}]
},{
	"value": "03",
	"text": "外国文学体裁",
	"description": "根据实际情况再添加子类目"
}]

module.exports = {
	modes,
	/**
	 * 根据模式获取名称
	 * 最后一项的text+倒数第二项的text
	 */
	getModeName: function(mode) {
		var res = ''
		const handleArray = (arr, lastObj) => {
			for (let i = 0; i < arr.length; i++) {
				if (arr[i].value === mode) {
					return arr[i].text + (lastObj ? lastObj.text : '')
				} else if (arr[i].children) {
					handleArray(arr[i].children, arr[i])
				}
			}
		}
		handleArray(modes)
		return res
	}
}